package com.alex.demo;


import java.util.Deque;
import java.util.LinkedList;

/**
 * 描述：
 * 给定一个以字符串表示的非负整数 num，移除这个数中的 k 位数字，使得剩下的数字最小。
 * 注意：
 * 移除 k 位数字后，剩下的数字不能有前导零，除非剩下的数字就是 0 本身。
 * 给定的 k 总是小于数字 num 的长度。
 * 示例：
 * 示例 1：
 * 输入：num = "1432219", k = 3
 * 输出："1219"
 * 解释：移除数字 4, 3, 2 后的最小数字是 1219。
 *
 * 1.1432219 -> 2219
 * 2.1432219 -> 1219
 * 3.1432219 -> 1419
 * 4.1432219 -> 1439
 * 5.1432219 -> 1432
 *
 * 目的：是得到数字最小的数字； 那么, 数字高位越高, 数字则越大; 越应该移除掉.
 *
 * 示例 2：
 * 输入：num = "10200", k = 1
 * 输出："200"
 * 解释：从原数字移除 1 后得到 0200。移除前导零后是 200。
 *
 * 示例 3：
 * 输入：num = "10", k = 2
 * 输出："0"
 * 解释：移除所有数字后是空字符串，需要表示为 "0"。
 *
 * 示例 4:
 * 输入：num5 := "54321" k = 3
 * 输出：21
 * 要求：
 * 输入：一个非负整数的字符串表示 num，一个整数 k。
 * 输出：移除 k 位数字后，剩下的最小数字的字符串表示。
 */
public class ProgramDemo {

    /**
     * 思路：
     * 1. 肯定不能排序; 否则数据就是错乱的.
     *
     * 整体数据不能乱, 只能抽调K的位置数据.
     *
     * 暴力：
     * 目的：是得到数字最小的数字； 那么, 数字高位越高, 数字则越大; 越应该移除掉.
     *
     * 同等长度的数字, 高位越大, 则数值越大.
     *
     * last: 若字符串长度> 1的时候, 需要清除掉最开始的头部0
     *
     * 输入：num = "1432219", k = 3
     *  * 输出："1219"
     *
     *  若比作一个链表; 那么删除之后的节点, 组成的数字, 进行MAth.min
     *  关键：删除的位置, 有
     *
     *  k代表1000起步
     */
    public static void main(String[] args) {
        System.out.println(removeKdigits("1432219", 3));
    }
//    String keyWord = "PIMJ970810HCHRRR06,MEIA890531HSLNZN02,PACE850515MNLLHL04,AADE920907HTCLZD02,SOVA971029HCHLLB07,GOAF880527MSLNQR14,ROGE751012MTSMRL07,AUMF920620MTCGNM02,RAOC820429MDFMJL07,TORC680416HDFRCT06,LOSL690504MDGPLR05,LOGR631030HDFPYC03,SANA910318HDFNVL03,FOAM740311HDFLLG09,CABO751229HCHRRS04,ZAIE701206MGRRSR02,VAHR950927HCSZRB00,EERM910801HYNCSG03,REVA700112HNLLLL04,AULG850210HSRCPB04,BACR640507MTSNSS08,RORF840121MTCDNL06,BANN670915MVZRLR06,HEAG021027HJCRGSA3,PAFF660921HDFLRR09,PAAI820112MJCLGV09,AAGC960229HMNLNR08,CEOL951208HBCSLS03,ROCC601203MDFJLL05,VEML830308HASRXS00,SAHC740716MDFNRR07,CUNG820902MCCRLN09,AIRS770924MVZVDS02,PULE741117HNLNZR07,UIXA680316MDFRXL01,OAEL751220MNLVLR03,SOGJ840720HVZSNN09,AUGL810215MGRGRS05,MOLO900707HCLNPM01,MOAI660122MCSRLS03,CABG770719MTSHNR00,MAMY041127MMCRNMA9,RESH610428HSLNLM06,HEME920726HMCRRD08,PACG760505HDFSSS09,RUTV671013MGRMXR09,IIPR600827HSRXVC08,GOFG610804HMSMGL05,CARA800924HNLCNR00,POHE590708MDFXRL07,GALC790604MSRMLL05,RARI900103HGRDMR01,CUGA930728HVZRRR05,MOBF800525HCLRLR02,BODC910926HSRRRR04,MAMP930919HSRCRD09,OAMM911114MNLVSR07,CUFD930516MSPRLN00,CUCR981031MBCRSY08,GOCD720129HDFNRV04,LECF900811HNLNRR00,COPM940928HCCLNG07,SUNA820822MNLRXN01,AAGG850211HSPMRL06,GARE790317MYNRZL07,PABF920714HPLDDR01,SAEM770526MDFNSR04,JUDE830520MCHRLM05,AUQR871202HNLGXL04,PESA780129MDFRNL04,LUHL740723MDFGRZ07,ROGL931014HSRBRS06,MAGJ970823HPLRTR03,GOPV810820HDFNRC08,MOHE951026HTLNRR07,REVR640924HVZYCD07,GUBG650602MJCZRD04,ROPC780917MMCSNR08,DIMM821130MDGZNN03,AACB851113HNTNRN03,MOAV701228MDFRLR00,REMJ911004HDFYRN01,GAGM780624MVZRNR00,VEFA850828MCMLGL05,VAPM631012MJCLRR03,LORG670110HVZPML06,GOCA740216HPLNRL05,GUPG651025MMCDPD03,DARC720911MCLVSR18,AUPR590729MCCGRS01,OEEN720526MDFRSM01,VICD630903MCLLRN00,VELR730228MDFLPC07,GUAE740816HCSLDD03,NIMR770305MCSXNS08,HECF640806HTSRRR05,RORG630412MJCDBL05,VEVN760723MDFRLR04,MOLD771229HMNRNV08,CARE830630HDFHMN00,ROGA620204MDFMRN09,MOGE850326MPLNLS09,FOBA800227MTSLSN02,RAAF640303HTCMRR01,MEAJ680223HSPNLN01,PEVI611121MSRRLR08,QUHB630415MGTNRL00,MUGJ610420HDFXNV00,GOCL940921HHGNRS09,EIAE850210MCCSRL01,CAAJ860612HDFRLS07,LOME610102HOCPNF09,AERO860507HHGRMS05,PERA710503HNLXSN05,AUVE851007MVZLLG06,MARL811215MVZRDC03,CUEA680930HDFRSL00,JIHS691020MCSMRC00,AUTF600501MNLGVL06,SAMY830226MCCNYN08,FARJ820902HDFRNN04,EARM681005HDFSYG05,BACL670305MYNLLR00,SELM750528MVZRPR00,CUMM930910MOCRRR02,DEVJ731226HSRCLR01,COLS881230MCSRPN01,GOHJ740603MVZNRN05,GADD890406HCLRZN03,ROVA730610HDFJLR06,LORP620429HOCPDD00,MAAA600409MDFLCN06,METR950911HDFJRL00,GORC660311HCLNSR04,SOVL770531MMNTRZ05,GORJ840219MCLNYS09,IATE790615HSRSRD07,CUSD680610HDFLLN09,REOC780321HMCBRS08,SACJ730319HCLLRS00,REML940929HDFNDS02,ROGA670829HDFDRB04,COEH710326HCMBSM03,LOGI971020MDFPRV07,MAMP750420HDFGLD05,PAAJ650810HSRCRN02,GASJ750414MVZRNS05,MOGC700806MNTNRL06,MOVK801114MGTNCR01,OIHJ860602HZSLRN13,CARR870523HTSSSM04,GUCJ750719HVZTRL06,CAMD741018HASMNN02,OXVF650831HGRXRL08,CUAV710113MHGRRR01,HESJ670604HMCRLS07,SACG820821HMCNRR08,MENE990818MCLDVR02,LOFB900910MBCPLL05,GAOF860326HSRLRR02,RORL870614MGTCYR01,AARG911020HVZVMR03,JICM960929HCCMNG04,RAAE631107HGTZRR03,GUVM620307MTSTZR09,RURR650405HTSZZG01,CASA670717HDFSPL06,PEAC720601HOCRQR00,AAGC760119HDFLTR00,BERA830410MPLRMN00,AAMR840115MMCLNS02,MAMR740104HPLTTN02,DOBR780926HSLMLB08,FEIT791225MSRLBR18,DUMJ650902HDFRDM01,IAMA991005HCLBRN02,DOOA760913HCHMNR01,GAFL830108MSLRLD05,CAGM600524MTSRTY08,CUPV920428MCSRZL02,AAME750725MMCYRV08,DAQS761025HSRVRT07,CUVV750302MJCRRR04,SABJ640208HDFNRN04,AABR700502HDFMRB01,CARE640315HCSLDM05,DAPK751104MBCVLR05,RAGM640719HJCMRN04,VEME710224MDFLNS04,HESC760811HDFRLS01,JICI690902HCSMRS09,AISM710519MJCVLR04,LAVS790129MTSZGL01,EUCA730121MMNSMR07,DALS600812HDFVGR00,GAHE801008HDFRRM09,SIAM800409MNLLGN04,LOOC720426HZSPRR07,JIBT630421HVZMRM06,VACP631128MVZZRT06,SAMJ750916HYNNYV05,AEGB890402MSPNNR04,VAAJ900317HTCLRS05,AATC790119HJCLRS08,LOII770919MCLPBS03,GARJ930708HTCRSN02,DIGR711227HJCZRG05,COTJ810712HDFRRS08,VICA680919HTCCRG00,PAVJ620904MJCDLS03,SAPH880925HSPNRC09,ROFM650726HVZSLR02,MUCA960305MVZXRD06,TOSM630925MOCRSR01,SARL831205MDFLML02,GAMA740102MDFRXR04,SAMV710511HCLLNC02,VEMG660111MVZRYL03,NAGN740102MTSVNR00,OAJE611228MDFSRL06,AEOP800715HDFRLD08,CAGC911011HNLBRS01,LOPJ920911HDFPCS04,RAPA640322MPLMSN12,SILJ921030HNLLNS00,JIOM681228MTCMVR08,GAGC811027MBCRNN00,TERC910516MNLRDY06,PORM701208HNLLYR03,OORA640809HDFRDL00,ZEHM830710MVZPRR02,CORE610104MDFLDL00,BAFJ950316HSRXJR02,LOCE860420MGRPRR09,VAGE601027HDFZND01,DAMM790604HTSRRT05,TEGE630413HHGRRL06,FACV920815HMNRMC01,AAVJ811221HSPRZS09,NAHN750127MNLVRC01,SASN771017MCSLLV06,GAAE890524HMSRND07,MOSJ660916HNLRPN09,HESJ730731HCSRNN09,GOAM830925MJCNRR00,CALJ670814HNLSXS03,DURA630721HVZRSL07,LAGC731214HVZNRR02,SILG590316HNTLPL03,TOOM820808HVZGLR03,VAQM620918MBCLJR01,BEAO640801HDFRLS08,RELF680302HDGNVD03,AESJ820725HJCRNQ09,FALL730914MNLRLR06,MAXF590420MSPRXR09,ROVK880923MVZSSR06,AEVP950213HCLRLZ02,JEFF841222HDFSLR09,RETC861023HDFYRR01,PXDA750714MDFRLN00,NOBE021212HQRJCDA2,ROGI910107HDFDTV04,AOOY630518MVZNCM05,EEEA911213HMCSSL00,CEMA650112HHGRRL00,MACL771004HDFTSS00,GAHR850616HMCLRB01,AEHR741012HHGRRC01,REMC690413HDFYXR02,LACR780404HDFNRN05,MERL800221HDFJBS07,MUGC890315HSRXLH02,TELC750817HVZLYR07,BANJ830901HPLRVS01,MACM670609MQRYHR00,BUAJ940504HSLNDB06,RERJ880228HDFYYN04,MOMJ910918HVZNNM03,CAMF791226HVZSRR07,MACF800821MSRRHB00,DUVC801208MCLRLN00,GUBL720116HMCTCP07,OASZ760815MDFSNH02,GUAG620521MPLVLB00,GABF621205HDFRZR07,CEOJ960303MDFRRN09,HECR771205HTCRRG08,AIEC820611HJCRSS03,BESY840311MMNRGL04,VAPE911013MDFRRR07,SAMR901130HCLLXC04,PAGJ000911HMCLNNA5,FEBD761127MMNRRL06,PIYV850411HYNXRC09,ZATG920517MCLVRD05,VIOF850417HDFLLR09,GOAO640719MMNNGF06,DOGM640511HGTMRR01,MAML970914HVZRRS00,OASF871004HQTRNR09,OIBL760705HTLRRS12,SAHL650806MYNNRZ06,VIPM740718HDFTRR00,PASC970507MVZSRN01,AARM720923MDFLMR08,PEOJ730408HMNRLN05,SAAH860120HGTNGG07,GAHM850815MTCRRR06,RIAL780118HJCVVB08,JEMY000216MVZSNRA0,MARM841111HTSRYR06,BELC720912MNLLJR09,OONC720916MDGCRR01,MOTA691216MDFRVN06,LEPA730701HYNLRL06,AAMR720724HDFRNC06,GAGH830411HDFYYR01,DIPG680623HCSZNL04,EUBJ910413HDFSNR02,AUDC590503MDFQLR06,RIMJ850130MGRVNN08,RORP590321MPLDMD08,GOQL600605HMSMNS02,MAFF760530HDFRRR05,SECD921201MVZGHN05,GATE740620MDFRRR03,GOFL750825HCMNLS08,ROLD840131MJCDPL03,SOEJ810802MCSLSS01,HIVA851029HCLDLR07,AIRS620908HCLTSR04,HEAE830309MNTRLR06,LATF620728HQTRJR03,TOPY800128HMNVRR05,SAOZ731105HDFNRR05,BOGJ021205HCHNRNA3,SOAP760223HGRTND01,CUCO720125HDFRRS04,AOND800326HDFRVN09,LARD750616HTLRYM08,CAPL750715HJCSLS01,OUSS631025MSLSRF07,GAJL820923HTCRVS06,JURJ731110MTSRBL01,AEHE650911MYNKRV06,VAXV620728HDFRXC02,RASD860313HNTMLV00,CASF831231HCMRLL02,EIEP911105MCLSSL01,ROCA681001MDFDHN01,GODJ910713HSRNVN02,FUMA700623MDFRRN02,VAGS660927MDGZRC08,EARD851003HMCSDN01,PECL800719MVZRRC03,RENT680528MDFYJR03,JIDJ950903HDFMMS18,OIAC760711MDGRRR03,ROCV780728MVZMBL05,VIAD600810HBCLLN08,MOSA850301HTLRND03,CAFA730421MSLSGD01,CARL710920MNLSZZ01,ROMA620212HGTJRR00,FOSR720514HVZLNB00,CAMG850204HJCBRL06,GAUA920802MTSRRN07,CASA870210HDFRNR02,COTF831221HNLRRR01,LUAA880824HSPNGL08,AAMM970115MMNLLR04,BEEB830112MDFLSN08,CAUJ841212HQRMCV00,CAPR681122HOCLCB18,MACL841205MPLRSD05,MACI880924MVZRHS00,CACE940729HDGBBD05,ROVM781020MVZCGR01,BECJ610218HYNNNN01,AULM660829HSRCPG07,TASJ621203HCSNNN00,RORN790726MDGMMR07,GUAA620915MPLRVD00,MOCM941003HCCRSG04,LOSA950826HNLPCN00,RARJ880412HCMMVR01,GOCM720823MDFNRRO8,MAGF760525HDGRMR02,GOMD690516HDFNRV00,REAM830226MMNYVR06,LANB630326HBCRTR00,CUSB610824MDFLNT03,MAMD810202MTCRYL01,RAMS720115MSRBDN06,RARD870319MMCMML03,AAMA830913MVZNRL05,LOLL711222HTCPPR07,EUCJ840603HQTSSN02,NAGE911213HMNVRR06,MEGD900420MVZNRL09,BAMR610507HJCTRM06,CIBJ910717HDFDRS07,SAMJ821216HGTLNN01,AAMS680801MGRRRN01,CADA861004HDFMRL06,DUGG810502HPLRNR05,AUCJ710904HJCGSN04,BAON980114HGTRRS03,AUSA930818HVZLLL06,ZARE860811MVZMDL06,VAMN650117MTSRTR00,GAMN750406MDFRXR07,CARA871121HVZSVL09,VAPJ900129HVZZLL02,SISS850628HDFLLL09,UXCP770720HYNCHD00,GOGA690310HSPNRL02,GIPR800508MDFRRC06,VIMJ890224HSRLXS09,CIAE831207MBSHMLO7,OEGV760224HDFLMC06,DIHB820908MSPZRT07,RASA930309HDGMGL03,CUBF771004HVZRNR07,AECO760915HOCLSS04,SAGM900608HDFNRS07,SAGJ841023HCLLNN02,GORT781102MDFMMN02,PORD760807HVZXDM03,CAMM630908HYNRNG09,GUCJ611114HASRRM04,FEEI840817MTSRSD08,GAGJ800304MSPTZN02,AUHP730122HCSRRD18,OIMA731002MDFRCN01,BOBM680819HSLRLN06,HOCV781124MYNBHR00,RACA710817HDFMRL00,IAOM811219MNLBRY01,HECJ810619HSLRRL07,RASR690606HTSMRB06,HEVR720608MVZRLS05,HECA670408HVZRZL00,AAGZ781031MMSLRX08,SALS971227MNLNJL06,JISJ961114HDFMLS02,AACI760502HDFYRS08,PANM780721MDFRRR03,BAPS830604MVZSRR01,DEBB010215MCLGLTA7,DEMJ800605HDFLRN05,CUDJ711225HVZPZS07,VAGL810208MGRLNT01,LOCC901218HTCPNR09,ROSE711124MMCDLD07,RAAA680622HVZMRR02,FAFR910311HVZRRC05,AAFD751103HDFRRV07,BAMM810725MGRRNY00,GODA841029MASNRD06,VAAA870413HCSZRD05,GOVC630427HDFNLR05,CUCG800312HTCRRB09,NEKE630823HCCGNL03,BAGH621221HVZRNG02,TOMM730303HVZRRS01,CAVJ630523HCLRLN03,LUGA900714MQTNNB05,AULJ751124HVZGPV04,LALO800922HVZRPZ04,VAVN830208MDGSLR06,ROMS760216HDFSNR04,GOQA611201HOCNRL02,GARC910413MVZRMN01,AULY770928MOCGCL08,RARF890920HCSMQR09,SAGJ810610HJCNZN07,CAXY921112MSLRXJ04,VAGC840625HDFLRH08,REHG810329MDFYRD04,BAAE730415HCHLRD08,FULA741203HTSNYL08,AUGO680207HCSGMM01,MXAS810217MNLNLL06,MARG931007MSPRCR09,GAMF691012HCSRNR04,MEAL900124HNLJRS01,GOHL860325HTSNRS08,MOOM980311HTCRSG05,CURE960713HQTRMN09,POVJ720426HSRBLN03,CESL770927MDFRNL04,DISE781231MGRZRV07,RACR780430MQTMLY12,VAOE910426HCSZCC09,HEAP600125HOCRNB08,HEHA620916MHGRRM02,CALU790516HMCRNB02,OOGM820929MTCSNG08,AACL700729MSLMHZ06,SOBA820530HJCTLL06,DAZA730116MCSMCR02,FOJA690930HDFLRR03,MAFA620913HTSLLR05,HERM790302MDGRDN08,CABC900920MCCBLR08,BAAG860429HDFLLS04,OOSL790621HTCCGS07,MAGT761214HPLRNM00,JURE971027MHGRMN03,PEBJ710102HCHRRS02,AOCA970731MJCGSD04,MEBA840602MJCNRN05,VXCA870519MTCSBL05,PEGF930912HCLRLB08,CAJJ950402HMNSMN02,GORL990117MOCNDC01,AEPG941124HJCRTD09,LUBJ970606HDGNRN08,SAGB701115MTCLRT06,PIPR950625MTSCDC00,NAEL750328MGTVLR03,VIRM620715MPLCMR02,TEHY880704MMNRRR02,OOFB020122HCLRRRA3,RORE620514MPLDMN06,BABL640825HDFRLS04,COMA700930MSRRRM05,GALJ940214HBCRLS09,SOMC790628HDFTRR05,RISR921229MMCVLS06,PACJ650214HDFTVV07,MACI620708MOCLRS06,ROLA820802HBCMPN03,CUHK951107MVZRRR06,TEVE910722HMCLZD06,GOOJ990213HGTNRN06,JIIL820409MVZMXR00,PAFR690103HCLMLM07,UAMM620214HYNCRR07,AALC950201MSRLRL05,GUCA880723MCSTBR01,HELH721230MOCRSN17,HECJ990323HCHRHV00,SOCN820223MHGLHT05,ROTB860307HPLDXR01,GASJ620121MDFRNL01,TOMA750219MPLRRL08,MARA701027HDFRJL07,RORJ050830MNLDSDA2,FOCY811212MDFLRD08,FUEL750308MDFNSR04,SOAI850514HSLTLS09,CAMA780323MDFSRN07,NIML600628MDFTJZ00,VAGG640509HVZRZL03,MAVK900726MTCRDY00,MAMJ630813HDFRYN03,FOGH010809HDFLRCA2,LIGH840601MJCNRL05,MAMJ821010HSPRRN01,LACE830320HJCZNS06,CICI010218MYNXMSA5,VEGA991227MBCGSL06,IAMC790713MJCBRL04,HICL941130HHGDLS03,AACC650523MCSLRN07,HAMS840916HNTRRR07,COCF840921HBCRBR07,LOGO641022MTSPJL01,RIHM960119HMCSRN04,HEPA840227MMSRRB02,NUMC741007HVZXTR02,GAGJ790402HTLRNN01,MOVR751007MVZTZS02,CAHJ831103MCCSRL04,REGG721021MMCYRB05,CAMF931116HSPSNL00,AEHF730418HDFLRR04,SAGP610926HNTNRB05,HEHM980825HMCRRN08,CAGS890202HVZSNR07,SAVT800601MCLNLR00,LUTJ710324MDFJRL03,VACJ960114HDFZBN06,LOSA890725HPLPRL03,LAPD861007HZSRRV06,GIGH820525HSPRNR06,COGL820519HVZRTS01,AAAH881005HMSLRC05,DUJJ820324HVZRMS02,RAAS620907HSLMRR08,SORV950114MGTTSR09,MAMA620408HPLRRL07,GAAA891030HTSRRM03,CACE010616HBCSMMA5,RAVD001012MGTMZNA8,ZAFH830702HNTMLR06,LOUA780615MBCPRH00,GACR780512HDGLHC03,TOCG660216HVZRRS00,VAVH750715HDFZLR07,CEHD860728HMCLRN02,GORS940611HGTNML07,OOCJ800906HGTRMN08,DIOD720902MPLZJL01,PALJ600519HVZZGS04,NARY870213MMCVYR05,VXGA590904HDFLRG06,MOVB870110MSLRZL06,COSA850102MCLNLD05,GUGA660422HDFZNL03,AEGR790416HOCNMG09,TAMM681230MVZLRR09,LUSF990210MDFNLR01,MUTY930701MCLXRL00,GARF820630MVZRYB06,GUCA681206MCSZRD02,TOCJ910529MDFRRC08,AAMG610625MDFLRL03,YACL721123MYNHHS00,MARM740303HDFRNN08,CAVM761129MCMHLN02,RUVJ801125HVZDZN08,BAGR690107HDFRRF07,MOSC891213HTCRNR01,FOAK940421MSLLLNO1,SOMP920123HTCSGB01,TENI830719MSPRTR06,CAHJ680513HPLSRN07,NICG631117MDFTLB05,HUMC850809MCHRCR05,OIRW670201HCLNBL07,IACM791114MSRBHR06,OEEJ871210HDFRSS06,MODA691218MSLNMR02,GAEI000306HJCNSSA2,GATG930927HCLRNR03,GAJB700529HDFLMRO5,HEEA730811MMCRSN01,MUAL831124HBSRVN08,CUCD870921MCCHRN01,GATG740610MJCRRR09,HERJ890509HCHRZN03,IARM600410HDFBDR02,RAPO990204HDFMRM09,LATD901215HHGRVV07,RACJ010922HTSMSSA6,REGE780215MDFYNL06,PESP970822HOCXNB09,OIVV951112HJCRLC09,PEAI610121MDFRRN09,EILM981209HVZSNR04,JIBL930313MVZMSZ06,VERL920506HDFLMS05,TOCN841223HGTRRX01,HELR720416MDFRMC07,PAVI921016MJCRRT09,VIMR621119HHGLRY09,AECA680721HCCRRR08,LOPA880608HOCPSN09,AUGN860407MJCGTN05,LORE980430HOCPVL01,PEBR860501MMCRRS03,RUAE960117HMCZRN08,LORR750707HVZPDM02,ZALG690822MBCMND03,ZAMN700221HNLPRL08,COVE770516MMNRGL04,SAVJ860220MDFRRS03,AOAF750823HCSMLL01,MAMM890511HNLSRG01,FUAS761017MDFNRT03,GAAE891015HTCRLD05,ROVC840418HGTDLR08,CACI830917HCHHLR12,RITP880501MGTCVL01,AASJ810922HSRLLN04,GAXR751123MOCMXY01,HESL911203MVZRNC03,RAST931013MMCMLN03,PICM590914MMCCRR04,CURM860208MVZRQR07,NICE890302HBCBMR06,GOVR810403HHGNLC03,CURF801120HVZRQL02,MIBG770625MDFRDR09,BIMG930726HCLRRD01,MARA910516MMSRCX04,HISA980630MTCPRN09,MEAI980405HCSNRS09,PUPK820607MCMLXR05,RORL910621HZSDYS00,CUGG740918HSRVLS02,RIZA910920MCLVNR04,CAGM870716MDFSLR04,HURM841029MZSZMY07,AAOH870702HDFLSG01,JIVJ630102MMCMZS00,LODJ860815MPLPMS02,GACJ681001HNLRNN02,LICJ750205HDFRNS03,MUGI740505HSLXDG06,MAPA671117HDFRXL01,EICJ840416HSLSMS08,GOHT890217HCSMRM09,HUOH910828HMCTRR05,AURS660906MVZGYR05,VIGL881028HDFDRS06,GAPI640603MNLRDD03,TOFT691221MVZRLR07,EASE660713MCSSNR03,GORN790519MCLNVN05,ROPA840922MCSDRD04,ROAL700628HVZGMS09,RIMS891215MBCVGR02,RERR951112HMCYYN02,OOMA980118MPLCRR00,AUSC041019MCCGNNA1,ZALM001229HMCRNGA9,PARN910516MMSDDM04,GARB700105MVZYNT02,UEMR760921MNLRDS06,OUNM770808HGRRVN03,JARL770809MVZRDR05,AEHG811121MVZLRD01,PAOM641226HMNCLR02,CIAM930619HYNHGG00,FONR800911MPLLVS03,GOCE610819HCSMBL08,RAVD971127MMCMGN01,HEML880624MDFRLL07,OOSO850426HDFSLL02,AEBK791115MJCNRR19,TERE650913MASRDL04,LEMO921129HVZYNM02,UOGR640302MTCLRS02,MILU740812HOCJPR05,TEPM960824HPLLRG09,REML831121HQTGRS04,RAMM781107HCSMRR06,CUCE690518HCCXXN00,JIDO900106HMSMMS09,GACE611022MPLRSL00,AUAR820706HMCGPP00,SAGR791022MDFNNB00,MEPA780625MPLNRN07,ROCR980412MMCDRB05,LACS870829HVZNSL03,POMA610424HMNNRL00,CAFM830526MYNBRR04,AAMT781009MDFLRN00,CXCA791102MDFSRR00,TEGR691211HDFLMC06,VAMD870622MTSRNN09,ROEM840415HNLDSR06,CATN660423MJCLRD09,GAPA630401MVZRRN03,DEFL710104MOCLNR01,MEMJ961127MBCNLC09,AAJA730705MTSLRN01,LARP670920MTSLMT07,MORM841011HPLNYR03,SOZL640612HVZLRS02,GOSI760205HDFNLS07,OEDG820202HMCCMD07,GOMA810612HJCNRL05,LOAC940924HVZPRR02,HECP981010MNTRRL00,CARL910604HDFHDS09,CUAE700923MOCRLD07,CAAC950816MQRSLN00,BAPN760711MDFTZN09,CAMR840120HGTSRM06,AUPL680129HCCGRS01,ROMS710918MCLDRF04,RAGE900901HTCYNL08,REGI770506MDFYRS03,TALR891222HMCPYY06,GARG870727MDFRYR00,EUGG720421MCCSRD00,MAAP751012MCLRGL08,EIAM901102MMCNYN09,AELA930830MCLRPZ05,REVG970718MMCYLD00,CAMF721014MSRBDR07,PALC641208MCCCZN09,HEFJ030817MGTRLSA2,BESD650822HNLRGV07,MAGL680201MDFTRT05,ROMD860626HGTDNV03,HEMF761101HMCRNR03,GULJ910818MMCRCZ07,MAGM870610HYNYRN04,QUCC790409HNLZSR02,SADN871212HDFNMS03,HEMV891108HCSRZC06,GOFN860226MTSNLH06,MACJ920925HYNRSR02,EIVF990614HPLLRR05,REVJ830212HNTYGR00,CIPB720306MYNHRL07,ROHA721019HDFSRL05,SARS780421MDFNMN01,ROHY911011MTSDRH06,DOSM860101HYNMBN05,TAGR760404MVZDLB00,GAHA801019HDFRRR02,SAGN620619HCCNRC05,LOHM690625MOCPRR04,LOZM920426MBCZZR08,BORJ660527HDFNZR04,LOZR871024HDFPPF04,AARF811003HCHLBL09,JIMS831221MCSMNS08,JEGE851030HOCRRS03,HEGA970724HOCRND06,ROCU890320HNTBRR04,COCA730929HQRCHR05,SARL800401HDFNZS07,MAVJ940926HBCCRS02,CILA770816HCLSLR02,BASY890608MDFRNN08,CAGR771202MDFZNC02,LAMD901108MVZRNN07,CAGF880530HMCMRR04,PEMK720514MSRRZR02,ROGC921101HDFMMH05,JAVC850125HDFRLH01,RORF660901HTSDSR03,AEGF890819MDFCMR04,PAEG680511MNLZCL02,VEGA750824MMCLLN03,LIGH710323MDFCLR09,GOHL660530MVZNRR06,LOAN750904MDFPGR09,VAHP840301HSPZRB06,AAGJ810121HHGMRL08,LOMR770329MTCPGS03,AARR860702MTCLQC00,HEVS930720MVZRGR03,AAVJ890223HDFLLL06,OORC950308HVZNYR06,EAMY790615MSPSRL00,LURJ840219MNLVMN05,TESE790707MDFRLN03,COMS680731HNLNRN09,PAHS760123HSLTRR00,ZACM850801HJCMHG09,BEEO730402MJCLSF09,LEHS681118MDFDRL07,GOTA700627HJCNVL03,COMY770411MVZBJN04,ROSC971116MBCMMR06,SASE990119MDFNND06,NIRC871123MMNTDT09,LORG820927MNLPCB05,UXCD870527MCCCHN07,MAFL730305MDFCLR09,EUGV010128HGTSRCA8,HEEL000407HMCRSSA5,PADH031124MBCTVDA9,GATA840420HMCLMG01,AUCE930323MJCNMR08,GOJC961112MMCNMR09,VACY940326MDFLRZ00,CIPA910624MNLSRN02,VIQI900817MMSLRN09,RALJ900330HMCMPN01,GAMA860617MVZRRL00,CAMJ921013HSPSRQ03,AELQ770504MOCLNN02,HUGE751004HDFRND02,AANS641105MBCLVC09,SAGV851021HCSLRC07,AACC870617HNTLRR08,ZEEE870217MSPRSR07,SUGJ880412MYNSNS09,ROLJ890405HDGSNV06,PANM831101HVZVVG09,HERD730115MTCRYL09,REHG851120HJCYRL05,HETM820210MVZRJR00,GABG920524HSRMRR00,PEMD830422HJCRJG09,RELM900425MGRFZR16,NAAS880710MJCVMN00,ROPF770911HSRDSR01,PEQG620110MCSRVD00,GURH760707HJCTZM05,MOAG770212MDFRRB08,MERG921022HTSNBB04,ROAA921001MBSMRZ01,TABR741229HMCPTY02,MOCD630928MNLRRL00,CALE960314HSLRZN07,AEAF811125HCCBGR09,MAOF010429HSPRRRA0,JICE800624MMCMCL03,COVJ660220HDFNLL09,CACE970820MCMSRS01,GUCA800409MCLRSL01,HUSR720801MDFRNS06,MAAM710504HTSLGN04,MASD940922MDFCNN02,DECM990114MMCLRR03,CELS840621MCLRPN07,BUCJ771127HCCNSN01,VEHJ850827HCCLRN03,SAGJ771028HDFRRN06,CARE801219HBCRMR10,SISD720127MOCMNR06,ROGA640329MTSLRN09,CUEY880922MYNRVL05,PECL920304HDFXVC05,CAMR840908HSPRNF05,MURM720610HDFRMR00,QUGA900726MMCRRN01,PEHM700607MVZRRR03,TOTB850729MDFRNT06,FICM771120MVZGRR08,OETP890530MDFRRR05,HUBK700531MDFRLR04,ROLJ671126HDFSRN05,DAMA820523MJCNGR00,DIPM610223HDFZCR09,BEGI800320MDFNNN00,CAAP620127MDFSNT06,GOCJ821226HJCMVS08,VAQE650703MCLLRL03,GOGJ801111HMCNNS06,MACM810407HCHGHC04,EIME850917MDFSNL04,GOKD860507HQRNHG00,SIRL810408MPLLDT07,GOTE670423HNLMVD01,ROMG961003HNLMDV05,TOVA830426MPLRLN07,BATM870704MSLRML00,MEVM910806HHGNRR01,MOMD750717HDFRRT00,MUEJ690208HDFXSS03,CUOA680609HDFRCR03,CAPD951228MDGRDN02,CAGR681230MNLRRB08,CARA910613MSPSDN03,HENI871223MGRRVS03,MALE640723MMNRNV02,VISJ970528MNLLCN00,COXC771104HNERXR06,OEFY641117MDFJGL06,CAMC621018MMCBRL06,EIHV670122HDFSRC06,ROFB730813HNLJRN13,JURT620917HMCSGD01,GAMA841001HTCRNL02,RIJE871125MMNVML06,GOCC920315MVZLSR04,GISJ730116MSPRNN09,CALL690516MNLMNS01,RAGI900517MVZMRL05,CAME880709HMCRNM08,CUPA800410MTCRRL02,GOGG880309MVZMTR01,BERB870803MDFLSL02,FIHL720310MCSGRC08,CXCA661212HCHLHL02,MOYL910411HSPRRN06,GUMG791011MCHTNR09,MAMN610505MNTRRR07,TARR620626HMCRYN01,MORL970804MMCRYZ05,COOE721108MDFRRL08,HETE760117MTCRRL03,UAFM690205HCCCRR06,BUNA920602HYNNVL06,VEMA710520MVZLLS06,NIRE721223HVZCDN00,BAJD751107HDFRMN00,OEPM800605HMNRRN04,BABS810227MSRRSN09,GACJ810429HDFRSN03,PEPR821112MHGRLN05,IASA730716HDFSNL07,ROEG710522HOCDNL00,AEML920427HPLRNS03,VIPJ680816HVZLNR00,MOHY680527MTSRRL01,MELO810901MMCNMR03,VAAA861221HDFLRN08,AATS891113HPLLLM07,CAPL780213MNTHNR04,PERV731103HJCRMC04,LOUV660614HDFPRC02,GAST710610HCLRNM07,MOSJ750307HDGRNR02,CAGS620818HDFHRR05";
    public static String removeKdigits(String num, int k) {
        Deque<Character> deque = new LinkedList<Character>();
        int length = num.length();
        for (int i = 0; i < length; ++i) {
            char digit = num.charAt(i);
            while (!deque.isEmpty() && k > 0 && deque.peekLast() > digit) {
                deque.pollLast();
                k--;
            }
            deque.offerLast(digit);
        }

        for (int i = 0; i < k; ++i) {
            deque.pollLast();
        }

        StringBuilder ret = new StringBuilder();
        boolean leadingZero = true;
        while (!deque.isEmpty()) {
            char digit = deque.pollFirst();
            if (leadingZero && digit == '0') {
                continue;
            }
            leadingZero = false;
            ret.append(digit);
        }
        return ret.length() == 0 ? "0" : ret.toString();
    }
}
